package egovframework.npqs.pqi.mobile.activity.quarantineresult;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;
import egovframework.npqs.pqi.mobile.AppStatus;
import egovframework.npqs.pqi.mobile.R;
import egovframework.npqs.pqi.mobile.activity.BuKipActivity;
import egovframework.npqs.pqi.mobile.activity.RelationDiseasePestActivity;
import egovframework.npqs.pqi.mobile.activity.approve.ApproveDetail;
import egovframework.npqs.pqi.mobile.activity.exportquarantineresult.ExportQuarantineResultDetail;
import egovframework.npqs.pqi.mobile.activity.quarantinerequest.QuarantineRequestDetailActivity;
import egovframework.npqs.pqi.mobile.common.Const;
import egovframework.npqs.pqi.mobile.jsoncontent.ErrorItem;
import egovframework.npqs.pqi.mobile.jsoncontent.QuarantineResultDetailItem;
import egovframework.npqs.pqi.mobile.jsoncontent.listitem.QuarantineDetailListItem;
import egovframework.npqs.pqi.mobile.jsonparser.QuarantineStatusDetailThread;
import egovframework.npqs.pqi.mobile.jsonparser.QuarantineStatusDetailThread.QuarantineStatusDetailThreadCallback;

//검역현황상세(검역결과현황상세)
public class QuarantineStatusDetail extends Activity implements OnClickListener
	, OnItemSelectedListener, QuarantineStatusDetailThreadCallback{
	private TextView titleTxt;	// 상단 타이틀
	private AppStatus myapp;
	private Context context;
	private String recNo, trnNmStr, trnCd;
	
	private ImageButton upBtn, downBtn, searchBtn, btnHome, btn_back;
	
	private EditText offCdEdit, requestNumEdit;	// 검역신청검역지 코드 에디트 박스, 검역신청 상세번호 에디트 박스
	
	private ListView listView;
	private QuarantineStatusDetailListAdapter quarantineDetailListAdapter;
	
	private TextView headerTotTxt, content11_1, place_director, success_reason, navigation, trnNm;
	private TextView content2_1, content2_2, content3_1, content4_1, content4_2;
	private TextView content5_1, content7_1, content7_2, photo_name, content10_1, content9_1, content8_1;
	
	private ImageButton button3_1, button10_1, bugi_button;
	private TextView button6_1, button6_2, button6_3, text_hwa_no, text_bl_no, text_quran_result;
	private EditText content10_2, content12_1, content_1_2, distinguish_edit, bugi_edit, bugi_detail_text;
	private RelativeLayout detail_layout6, layout_distinguish, layout_bugi, layout_bugi_detail, layout_distinguish_edit;
	private RelativeLayout line_bugi_text, line_distinguish;
	
	private QuarantineResultDetailItem quarantineResultItem;
	private QuarantineStatusDetailThread quarantineThread;
	private ArrayList<QuarantineDetailListItem> prodArrList;
	
	private Button footerBtn01, footerBtn02, footerBtn03, footerBtn04;	// 하단 버튼
	private final static int MSG_QUARANTINE_COMPLETED = 0;
	private final static int MSG_QUARANTINE_ERROR = 1;
	private final static int MSG_NETWORK_ERROR = 2;
	
	private Intent intent;
	private boolean searchState;
	//타이틀을 정할때 수출검역현황상세인지, 수입인지 확인하는 변수
	private String isExport;
	private RelativeLayout layout_hwa_no, layout_bl_no, layout_quran_result;
	
	//사진
	private RelativeLayout photo_check_mgs, detail_layout13_1;
	private ImageView photo_view, photo_view2;
	private Drawable drawable1, drawable2;
	private String url1, url2;
	
	//하단 리스트 해더
	private LinearLayout list_header_Layout;
	
	private boolean firstLoad;
	
	private String mResult;
	
	/* G-MOBILE 변수*/
    private String temp;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		firstLoad= true;
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_quarantine_status_detail);
		
		Intent intent = getIntent();
		recNo = intent.getStringExtra("recNo");
		isExport = intent.getStringExtra("isExport");
		if(isExport.toString().equals("true")){
			AppStatus.navigation.addPathLocation("수출검역현황상세");
		}else{
			AppStatus.navigation.addPathLocation("수입검역현황상세");
		}
		init();
	}
	
	private void init(){
		context = this;
		myapp = (AppStatus) getApplicationContext();
		myapp.startBroker(context);
		
		titleTxt = (TextView)findViewById(R.id.headerTitleText);
		if(isExport.toString().equals("true")){
			titleTxt.setText("수출검역현황상세");
		}else{
			titleTxt.setText("수입검역현황상세");
		}
		
		navigation = (TextView)findViewById(R.id.navigation);
		navigation.setText(AppStatus.navigation.getPath());
		Log.i("AppStatus.navigation.getPath()->", AppStatus.navigation.getPath());
		
		//하단 리스트 해더
		list_header_Layout = (LinearLayout)findViewById(R.id.list_header_Layout);
		list_header_Layout.setVisibility(View.VISIBLE);
		
		offCdEdit = (EditText)findViewById(R.id.content_1_1);
		offCdEdit.setText(myapp.getLoginItem().getOffCd());
		
		requestNumEdit = (EditText)findViewById(R.id.content_1_2);
		requestNumEdit.setText(recNo);
		
		searchBtn = (ImageButton)findViewById(R.id.search_btn);
		searchBtn.setOnClickListener(this);
		
		/*loginBtn = (ImageButton)findViewById(R.id.btnLogin);
		loginBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				myapp.appFinish(QuarantineStatusDetail.this);				
			}
		});*/
		
		btn_back = (ImageButton)findViewById(R.id.btn_back);
		btn_back.setVisibility(View.VISIBLE);
		btn_back.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				onBackPressed();
			}
		});
		
		btnHome = (ImageButton)findViewById(R.id.btnHome);
		btnHome.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				myapp.setAbleHome(true);
				finish();
			}
		});
		
		searchState = false;
		listView = (ListView)findViewById(R.id.qua_detail_list);
		quarantineDetailListAdapter = new QuarantineStatusDetailListAdapter();
		
		layout_distinguish = (RelativeLayout)findViewById(R.id.layout_distinguish);
		layout_bugi = (RelativeLayout)findViewById(R.id.layout_bugi);
		layout_distinguish_edit = (RelativeLayout)findViewById(R.id.layout_distinguish_edit);
		layout_bugi_detail = (RelativeLayout)findViewById(R.id.layout_bugi_detail);
		
		//line layout
		line_bugi_text = (RelativeLayout)findViewById(R.id.line_bugi_text); 
		line_distinguish = (RelativeLayout)findViewById(R.id.line_distinguish);
		
		footerBtn01 = (Button)findViewById(R.id.footer01Btn);
		footerBtn02 = (Button)findViewById(R.id.footer02Btn);
		footerBtn03 = (Button)findViewById(R.id.footer03Btn);
		footerBtn04 = (Button)findViewById(R.id.footer04Btn);
		
		content2_1 = (TextView)findViewById(R.id.content_2_1);
		content2_2 = (TextView)findViewById(R.id.content_2_2);
		content3_1 = (TextView)findViewById(R.id.content_3_1);
		content4_1 = (TextView)findViewById(R.id.content_4_1);
		content4_2 = (TextView)findViewById(R.id.content_4_2);
		content5_1 = (TextView)findViewById(R.id.content_5_1);
		content7_1 = (TextView)findViewById(R.id.content_7_1);
		content7_2 = (TextView)findViewById(R.id.content_7_2);
		content10_1 = (TextView)findViewById(R.id.content_10_1);
		place_director = (TextView)findViewById(R.id.place_director);
		success_reason = (TextView)findViewById(R.id.success_reason);
		text_hwa_no = (TextView)findViewById(R.id.text_hwa_no); //화물번호
		text_bl_no = (TextView)findViewById(R.id.text_bl_no); //bl번호
		text_quran_result = (TextView)findViewById(R.id.text_quran_result); //검역결과
		trnNm = (TextView)findViewById(R.id.trnNm); //검역결과
		
		button3_1 = (ImageButton)findViewById(R.id.button_3_1);
		
		/*긴급제한, 수입금지, 관련병해충*/
		//긴급제한
		//자료없음...
		button6_1 = (TextView)findViewById(R.id.button_6_1);
		button6_1.setText(Html.fromHtml("<u>긴급제한</u>"));
		button6_1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				intent = new Intent(QuarantineStatusDetail.this, RelationDiseasePestActivity.class);
				intent.putExtra("value", "1");
				intent.putExtra("natCd", quarantineResultItem.getNatCd());
				intent.putExtra("offCd", myapp.getLoginItem().getOffCd());
				intent.putExtra("recNo", quarantineResultItem.getRecNo());
				startActivity(intent);
			}
		});
		//수입금지
		button6_2 = (TextView)findViewById(R.id.button_6_2);
		button6_2.setText(Html.fromHtml("<u>수입금지</u>"));
		button6_2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				intent = new Intent(QuarantineStatusDetail.this, RelationDiseasePestActivity.class);
				intent.putExtra("value", "2");
				intent.putExtra("natCd", quarantineResultItem.getNatCd());
				intent.putExtra("offCd", myapp.getLoginItem().getOffCd());
				intent.putExtra("recNo", quarantineResultItem.getRecNo());
				startActivity(intent);
			}
		});
		//관련병해충
		//http://211.47.133.100:8086/index.do?paramTarget=REQ027&searchType=000&searchNatCd=402&searchOffCd=20&searchRecNo=14011260
		//안나옴...
		button6_3 = (TextView)findViewById(R.id.button_6_3);
		button6_3.setText(Html.fromHtml("<u>관련병해충</u>"));
		button6_3.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				intent = new Intent(QuarantineStatusDetail.this, RelationDiseasePestActivity.class);
				intent.putExtra("value", "3");
				intent.putExtra("natCd", quarantineResultItem.getNatCd());
				intent.putExtra("offCd", myapp.getLoginItem().getOffCd());
				intent.putExtra("recNo", quarantineResultItem.getRecNo());
				startActivity(intent);
			}
		});
		
		button10_1 = (ImageButton)findViewById(R.id.button_10_1);
		bugi_button = (ImageButton)findViewById(R.id.bugi_button);
		
		content8_1 = (TextView)findViewById(R.id.content_8_1);
		content11_1 = (TextView)findViewById(R.id.content_11_1);
		content9_1 = (TextView)findViewById(R.id.content_9_1);
		content10_2 = (EditText)findViewById(R.id.content_10_2);
		content12_1 = (EditText)findViewById(R.id.content_12_1);
		//검역신청번호 뒷자리
		content_1_2 = (EditText)findViewById(R.id.content_1_2);
		distinguish_edit = (EditText)findViewById(R.id.distinguish_edit);
		bugi_edit = (EditText)findViewById(R.id.bugi_edit);
		bugi_detail_text = (EditText)findViewById(R.id.bugi_detail_text);
		
		detail_layout6 = (RelativeLayout)findViewById(R.id.detail_layout6);
		layout_hwa_no = (RelativeLayout)findViewById(R.id.layout_hwa_no);
		layout_bl_no = (RelativeLayout)findViewById(R.id.layout_bl_no);
		layout_quran_result = (RelativeLayout)findViewById(R.id.layout_quran_result);
		
		//연락처 누르면 전화걸기
		content4_2.setPaintFlags(content4_2.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
		content4_2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Uri n = Uri.parse("tel: "+content4_2.getText());
				startActivity(new Intent(Intent.ACTION_DIAL, n));
			}
		});
		
		//사진
		detail_layout13_1 = (RelativeLayout)findViewById(R.id.detail_layout13_1);
		photo_check_mgs = (RelativeLayout)findViewById(R.id.photo_check_mgs);
		photo_view = (ImageView)findViewById(R.id.photo_view);
		photo_view2 = (ImageView)findViewById(R.id.photo_view2);
		
		//footerBtn01.setOnClickListener(this);
		footerBtn02.setOnClickListener(this);
		footerBtn03.setOnClickListener(this);
		footerBtn04.setOnClickListener(this);
		
		footerBtn01.setBackgroundResource(R.drawable.f_blank_sel);
		//하단버튼 2, 4번째꺼 검역결과등록, 검역신청으로 변경
		footerBtn02.setBackgroundResource(R.drawable.foot03_request_selector);
		footerBtn04.setBackgroundResource(R.drawable.foot_quarantine_selector);
		
		myapp.showDialogNo(context);
		temp = "처음검색";
		//asyncTaskIsConnectedVPN();
		threadStart();
		
	}
	
	//상단 조회버튼 누르면 조회가 시작된다.
	private void searchDetail(){
		searchState = true;
		//headerTotTxt.setText("");
		
		myapp.showDialogNo(context);
		temp = "조건검색";
		myapp.utilm.InputKeybordHidden(context, requestNumEdit);
		//asyncTaskIsConnectedVPN();
		threadStart();
		
	}
	
	public void threadStart(){
		if("조건검색".equals(temp)){
    		quarantineThread = new QuarantineStatusDetailThread(context, this
    				, myapp.getLoginItem().getOffCd(), requestNumEdit.getText().toString()
    				, AppStatus.getmUserId());
    		quarantineThread.start();
    	}
    	if("처음검색".equals(temp)){
    		quarantineThread = new QuarantineStatusDetailThread(context, this
    				, myapp.getLoginItem().getOffCd(), recNo, AppStatus.getmUserId());
    		quarantineThread.start();
    	}
	}
	
	private void layoutSetting() {
		trnCd = quarantineResultItem.getTrnCd().trim();
		trnNmStr = quarantineResultItem.getTrnNm().trim();
		
		trnNm.setText(quarantineResultItem.getTrnNm());
		content2_1.setText(quarantineResultItem.getResOffCd() 
				+"-"+quarantineResultItem.getResNo());
		content2_2.setText(quarantineResultItem.getResultProgrsNm());
		content3_1.setText(quarantineResultItem.getVenNm());
		content4_1.setText(quarantineResultItem.getVenRep());
		content4_2.setText(quarantineResultItem.getVenTelNo());
		content5_1.setText(quarantineResultItem.getNatNm());
		content7_1.setText(quarantineResultItem.getDelayNm());
		content7_2.setText(quarantineResultItem.getDelayRcognAt());
		content8_1.setText(quarantineResultItem.getValidflagNm());
		content9_1.setText(quarantineResultItem.getInsPlace());
		
		content10_1.setText(quarantineResultItem.getQuranNm1()
				+"   "+quarantineResultItem.getQuranNm2());
		content11_1.setText(quarantineResultItem.getPassResrveReasonNm());
		content12_1.setText(quarantineResultItem.getRemark());
		place_director.setText("현장검역관");
		success_reason.setText("합격보유사유");
		text_hwa_no.setText(quarantineResultItem.getHwaNo());
		text_bl_no.setText(quarantineResultItem.getBlNo());

		//수출, 수입 나눠서 레이아웃 보이기
		/*String trnCd = quarantineResultItem.getTrnCd();
		System.out.println("trnCd : "+trnCd);*/
		
		//수출일경우 dMark(Dishtinguish Mark) 표시
		//수출일경우 remCd(부기사항)표시
		if(trnNmStr.equals("수출")&&firstLoad){
			firstLoad=false;
			layout_distinguish.setVisibility(View.VISIBLE);
			layout_distinguish_edit.setVisibility(View.VISIBLE);
			line_distinguish.setVisibility(View.VISIBLE);
			layout_bugi.setVisibility(View.VISIBLE);
			layout_bugi_detail.setVisibility(View.VISIBLE);
			line_bugi_text.setVisibility(View.VISIBLE);
			layout_hwa_no.setVisibility(View.GONE);
			layout_bl_no.setVisibility(View.GONE);
			layout_quran_result.setVisibility(View.VISIBLE);
			
			distinguish_edit.setText(quarantineResultItem.getdMark());
			bugi_edit.setText(quarantineResultItem.getRemCd());
			bugi_detail_text.setText(quarantineResultItem.getRemNm());
			bugi_button.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					Intent intent = new Intent(context, BuKipActivity.class);
					intent.putExtra("remCd", bugi_edit.getText().toString());
					startActivityForResult(intent, 1);
				}
			});
			
			Log.i("resultFlag", quarantineResultItem.getResultFlag());
			if(quarantineResultItem.getResultFlag().equals("226001")){
				//합격
				text_quran_result.setText("합격");
			}else if(quarantineResultItem.getResultFlag().equals("226002")){
				//불합격
				text_quran_result.setText("불합격");
			}else{
				//보류
				text_quran_result.setText("보류");
			}
		}
		
		//사진보기
		/*url1 = photoSetting(quarantineResultItem.getImgResult1()).replace("\\", "/");
		url2 = photoSetting(quarantineResultItem.getImgResult2()).replace("\\", "/");
		if(!"".equals(url1)||null!=url1){
			detail_layout13_1.setVisibility(View.VISIBLE);
			photo_check_mgs.setVisibility(View.GONE);
			photo_view.setVisibility(View.VISIBLE);
			new yourTask().execute();
		}
		if(!"".equals(url2)||null!=url2){
			photo_view2.setVisibility(View.VISIBLE);
			new yourTask().execute();
		}*/
		//사진보기
		
		if("".equals(quarantineResultItem.getImgResult1().trim())){
			url1="";
		}else{
			detail_layout13_1.setVisibility(View.VISIBLE);
			photo_check_mgs.setVisibility(View.GONE);
			photo_view.setVisibility(View.VISIBLE);
			url1 = photoSetting(quarantineResultItem.getImgResult1()).replace("\\", "/");
			new yourTask().execute();
		}
		if("".equals(quarantineResultItem.getImgResult2().trim())){
			url2 = "";
		}else{
			photo_view2.setVisibility(View.VISIBLE);
			url2 = photoSetting(quarantineResultItem.getImgResult2()).replace("\\", "/");
			new yourTask().execute();
		}
		
		//photoSetting(quarantineResultItem.getImgResult2());
		
		/*긴급제한, 수입금지, 관련병해충*/
		// 과태료 여부 안보이게
		/*if(!quarantineResultItem.getPzsCnt().equals("0")){	
			button3_1.setVisibility(View.VISIBLE);
		}*/
		// 긴급제한 여부 안보이게
		if(!quarantineResultItem.getPenCnt().equals("0")){	
			button6_1.setVisibility(View.VISIBLE);
		}
		// 수입금지 안보이게
		if(!quarantineResultItem.getExpCnt().equals("0")){	
			button6_2.setVisibility(View.VISIBLE);
		}
		// 관련병해충 안보이게
		if(!quarantineResultItem.getDbyhsCnt().equals("0")){	
			button6_3.setVisibility(View.VISIBLE);
		}
		// 한줄 없애기
		if(!quarantineResultItem.getPenCnt().equals("0") ||
				!quarantineResultItem.getExpCnt().equals("0") ||
				!quarantineResultItem.getDbyhsCnt().equals("0")){	
			detail_layout6.setVisibility(View.VISIBLE);
		}
		
		
		listView.setVisibility(View.VISIBLE);
		prodArrList = quarantineResultItem.getItems();
		
		//prodArrList.
		
		headerTotTxt = (TextView)findViewById(R.id.header_tot);
		upBtn = (ImageButton)findViewById(R.id.header_up_btn);
		downBtn = (ImageButton)findViewById(R.id.header_down_btn);
		
		//검역현황상세 하단 리스트 제목
		Log.i("getItemsResult", "getItemsResult 출력된다. : "+quarantineResultItem.getItemsResult());
		//error01
		headerTotTxt.setText("총 품목:" + quarantineResultItem.getItemsResult() + "건");
		Log.i("headerTotTxt", "headerTotTxt.getText : "+headerTotTxt.getText());
		
		listView.setAdapter(quarantineDetailListAdapter);
		upBtn.setOnClickListener(this);
		downBtn.setOnClickListener(this);
		
		downBtn.performClick();
		
	}
	
	private class yourTask extends AsyncTask<Integer, Void, Integer> {
	    @Override
	    protected void onPreExecute() {
	        super.onPreExecute();
	        //show a progress bar
	    }
	    @Override
	    protected Integer doInBackground(Integer... params) {
	        drawable1  =  myapp.cameraUtil.LoadImageFromWeb(url1); 
	        drawable2  =  myapp.cameraUtil.LoadImageFromWeb(url2); 
	        return 0; 
	    }      
	    @Override
	    protected void onPostExecute(Integer result) {
	        super.onPostExecute(result);
	        photo_view.setImageDrawable(drawable1);   
	        photo_view2.setImageDrawable(drawable2);  
	    }
	}
	public String photoSetting(String img){
		String ImgResult=img;
		System.out.println("img : "+img);
		String url=Const.MAIN_URL;
		if(!"".equals(img)||null!=img){
			url = url.replaceAll("/index.do","");
			url += ImgResult;
		}
		return url;
	}
	
	@Override
	public void onClick(View v) {
		Intent intent ;
		switch (v.getId()) {
		
		//상단 조회 버튼
		case R.id.search_btn:
			if(content_1_2.getText().toString().length()==8){
				headerTotTxt.setText("");
				searchDetail();
			}else{
				myapp.utilm.ShowDialog(context, "실패", "검역신청 번호 뒤 8자리를 입력해 주세요.", 20);
			}
			break;
		
		//목록 버튼
		case R.id.footer01Btn:	
			onBackPressed();
			break;
			
		//검역결과등록 버튼
		case R.id.footer02Btn:	
			//수입(trnCd) : 173003, 173004
			if(trnNmStr.equals("수입")){
				intent = new Intent(QuarantineStatusDetail.this, QuarantineResultDetail.class);
				intent.putExtra("recNo", quarantineResultItem.getRecNo());
				startActivity(intent);
			}
			//수출(trnCd) : 173001, 173002
			if(trnNmStr.equals("수출")){
				intent = new Intent(QuarantineStatusDetail.this, ExportQuarantineResultDetail.class);
				intent.putExtra("recNo", quarantineResultItem.getRecNo());
				startActivity(intent);
			}
			
			/*intent = new Intent(QuarantineStatusDetail.this, QuarantineResultDetail.class);
			intent.putExtra("recNo", quarantineResultItem.getRecNo());
			startActivity(intent);*/
			break;
			
		//결제 버튼
		case R.id.footer03Btn:	
			if(quarantineResultItem.getResultProgrsSt().equals("377002") && quarantineResultItem.getDelaysayu().equals("342001")){
				intent = new Intent(QuarantineStatusDetail.this, ApproveDetail.class);
				intent.putExtra("resNo", quarantineResultItem.getResNo());
				intent.putExtra("resOffCd", quarantineResultItem.getResOffCd());
				intent.putExtra("value", "0");
				startActivity(intent);
			}else{
				myapp.utilm.ShowDialog(QuarantineStatusDetail.this, "실패", "저장을 먼저 해주세요.", 20);
			}
			break;
			
		//검역신청 버튼
		case R.id.footer04Btn:	
			intent = new Intent(QuarantineStatusDetail.this, QuarantineRequestDetailActivity.class);
			intent.putExtra("recNo", quarantineResultItem.getRecNo());
			startActivity(intent);
			break;
			
		//하단 품목 리스트 위화살표
		case R.id.header_up_btn:
			RelativeLayout.LayoutParams listParams = new RelativeLayout.LayoutParams
		    (LayoutParams.WRAP_CONTENT, myapp.utilm.getDpToPixel(context, 400));
			listParams.addRule(RelativeLayout.ABOVE, R.id.bottom_layout);
			listView.setLayoutParams(listParams);
			break;
			
		//하단 품목 리스트 아래 화살표
		case R.id.header_down_btn:
			RelativeLayout.LayoutParams listParams1 = new RelativeLayout.LayoutParams
		    (LayoutParams.WRAP_CONTENT, myapp.utilm.getDpToPixel(context, 54));
			listParams1.addRule(RelativeLayout.ABOVE, R.id.bottom_layout);
			listView.setLayoutParams(listParams1);
			break;			

		default:
			break;
		}
		
	}
	
	private Handler handler = new Handler() {
		@Override
		public void handleMessage(final Message msg) {
			switch (msg.what) {
			case MSG_QUARANTINE_COMPLETED:
				layoutSetting();
				break;

			case MSG_QUARANTINE_ERROR:
				String errMsg = "";
				if(msg == null ||msg.obj.toString().equals("")){
					errMsg = "서버와의 연결에 실패하였습니다.";
				}else{
					errMsg = msg.obj.toString();	
				}
				
				myapp.utilm.ShowDialog(QuarantineStatusDetail.this, "실패", errMsg, 20);
				
				break;

			case MSG_NETWORK_ERROR:
				myapp.utilm.ShowDialog(QuarantineStatusDetail.this, "실패", "네트워크에러", 20);

			default:
				break;
			}
		}
	};
	
	class QuarantineStatusDetailListAdapter extends BaseAdapter {
		TextView detail_list_seq, detail_list_trfclsf_cd, detail_list_item_type;
		TextView detail_list_itm_qty, detail_list_prod_name, detail_list_ins_qty, detail_list_hs_cd;
		
		@Override
		public int getCount() {
			return prodArrList.size();
		}

		@Override
		public Object getItem(int position) {
			return prodArrList.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {
			if (convertView == null || convertView != null) {
    			LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    			convertView = inflater.inflate(R.layout.list_status_detail_item, parent, false);
    		}
			
			detail_list_seq = (TextView)convertView.findViewById(R.id.detail_list_seq);
			detail_list_trfclsf_cd = (TextView)convertView.findViewById(R.id.detail_list_trfclsf_cd);
			detail_list_itm_qty = (TextView)convertView.findViewById(R.id.detail_list_itm_qty);
			detail_list_prod_name = (TextView)convertView.findViewById(R.id.detail_list_prod_name);
			detail_list_item_type = (TextView)convertView.findViewById(R.id.detail_list_item_type);
			detail_list_ins_qty = (TextView)convertView.findViewById(R.id.detail_list_ins_qty);
			detail_list_hs_cd = (TextView)convertView.findViewById(R.id.detail_list_hs_cd);
			
			detail_list_seq.setText(prodArrList.get(position).getRecSeq());
			detail_list_trfclsf_cd.setText(prodArrList.get(position).getPrdlstCode());
			detail_list_itm_qty.setText(prodArrList.get(position).getItmQty());
			detail_list_prod_name.setText(prodArrList.get(position).getPrdlstNm());
			detail_list_ins_qty.setText(prodArrList.get(position).getInsQty());
			detail_list_item_type.setText(prodArrList.get(position).getItemType());
			detail_list_hs_cd.setText(prodArrList.get(position).getHsCd());
			
			convertView.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					listItemClickEvent(position);
				}
			});
			
			return convertView;
		}
		
		private void listItemClickEvent(final int position) {}
	}
	@Override
	public void onItemSelected(AdapterView<?> parent, View view, int position,
			long id) {}

	@Override
	public void onNothingSelected(AdapterView<?> parent) {}

	@Override
	public void OnQuarantineStatusDetailCompleted(boolean isNetworkConntected,
			QuarantineResultDetailItem quarantineItem, String message) {
		
		//new
		Log.i("message-->", "message-->"+message);
		if(null != message && !"".equals(message)){
			mResult = message;
			reesultToast();
		}
		
		if(myapp.dialog !=null && myapp.dialog.isShowing()) {
			myapp.dialog.dismiss();
		}
		
		if(!isNetworkConntected){	// 네트워크 접속이 되어 있지 않을 때
			Message msg = handler.obtainMessage();
			msg.what = MSG_NETWORK_ERROR;
			handler.sendMessage(msg);
			return;
		}
		
		if(quarantineItem != null) {
			this.quarantineResultItem = quarantineItem;
			Message msg = handler.obtainMessage();
			msg.what = MSG_QUARANTINE_COMPLETED;
			handler.sendMessage(msg);
		}
	}

	@Override
	public void OnQuarantineStatusDetailError(ErrorItem errorItem) {
		if(myapp.dialog !=null && myapp.dialog.isShowing()) {
			myapp.dialog.dismiss();
		}

		Message msg = handler.obtainMessage();
		msg.what = MSG_QUARANTINE_ERROR;
		if(errorItem != null) {
			msg.obj = errorItem.getrDesc();
		}
		handler.sendMessage(msg);
	}
	
	@Override
	protected void onResume() {
		if(myapp.isFinishState()||myapp.isAbleHome()){
			finish();
		}
		if(myapp.isDataDetailLoadState()){
			myapp.startBroker(context);
			layoutSetting();
			myapp.setDataDetailLoadState(false);
		}
		super.onResume();
	}
	/*@Override
	protected void onRestart() {
		searchBtn.performClick();
		super.onRestart();
	}*/
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		switch (requestCode) {
		case 1: //부기사항버튼
			if(resultCode == 1){
				bugi_edit.setText(data.getStringExtra("bukipCd"));
				bugi_detail_text.setText(data.getStringExtra("bukipNm"));
			}else{
				Log.i("resultCode","resultCode  0 아님");
			}
			break;

		default:
			break;
		}
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		AppStatus.navigation.delPathLocation();
	}
	
	private void reesultToast() {
		runOnUiThread(new Runnable() {

            public void run() {
                Toast toast = Toast.makeText(context, mResult, Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 50);
                toast.show();
            }
        });
    }
}